package com.example.demo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public abstract class Champion extends GameObject{

    //移动
    public boolean up,down,left,right;
    //移动图集
    static String[] imgs = new String[3];
    //第几张图片
    int moveCount = 1;
    //技能图片
    Image abilityOne;
    Image abilityTwo;
    Image abilityThree;
    //技能冷却时间
    int coolDownTimeOne;
    int coolDownTimeTwo;
    int coolDownTimeThree;
    //三个技能是否在冷却时间
    boolean coolDownOne = true;
    boolean coolDownTwo = true;
    boolean coolDownThree = true;


    static {
        for (int i = 1;i < 3;i++){
            imgs[i] = "img/move/" + i + ".png";
        }
    }

    public Champion(GameFrame gameFrame) {
        super(gameFrame);
        setImg("img/stand.png");
        setX(700);
        setY(3800);
        setSpd(55);
        setHp(24000);
        setDis(250);
        setAttackCoolDownTime(1000);
        setCurrentHp(getHp());
    }

    public void KeyPressed(KeyEvent e){
        int key = e.getKeyCode();
        if(key == KeyEvent.VK_D){
            right = true;
        }
        if (key == KeyEvent.VK_A){
            left = true;
        }
        if (key == KeyEvent.VK_W){
            up = true;
        }
        if (key == KeyEvent.VK_S){
            down = true;
        }
    }

    public void KeyReleased(KeyEvent e){
        int key = e.getKeyCode();
        if(key == KeyEvent.VK_D){
            right = false;
        }
        if (key == KeyEvent.VK_A){
            left = false;
        }
        if (key == KeyEvent.VK_W){
            up = false;
        }
        if (key == KeyEvent.VK_S){
            down = false;
        }
    }

    public void move(){
        if (up){
            setY(getY() - getSpd());
        }
        if (down){
            setY(getY() + getSpd());
        }
        if (left){
            setX(getX() - getSpd());
        }
        if (right){
            setX(getX() + getSpd());
        }
        if (up||down||left||right){
            setImg(imgs[moveCount]);
            moveCount ++;
            if (moveCount == 3){
                moveCount = 1;
            }
        }else {
            setImg("img/stand.png");
        }
    }

    //添加三个技能按钮
    public void addButton(){
        JButton button1 = new JButton();
        button1.setSize(100,100);
        button1.setLocation(1056,513);
        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("ability one");
            }
        });
        JButton button2 = new JButton();
        button2.setSize(100,100);
        button2.setLocation(1090,370);
        button2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("ability two");
            }
        });
        JButton button3 = new JButton();
        button3.setSize(100,100);
        button3.setLocation(1220,300);
        button3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("ability three");
            }
        });
        gameFrame.add(button1);
        gameFrame.add(button2);
        gameFrame.add(button3);
    }

    public abstract void abilityOne();
    public abstract void abilityTwo();
    public abstract void abilityThree();
    public abstract void abilityEffect();

    @Override
    public Rectangle getRec() {
        return new Rectangle(getX() - 30,getY() - 60,60,120);
    }

    @Override
    public void paintSelf(Graphics g) {
        //生命值为0
        if (getCurrentHp()<=0){
            setAlive(false);
            gameFrame.removeList.add(this);
        }else {
            //添加生命
            addHp(g, 30, 80, 80, 20, Color.GREEN);
            //绘制图片
            g.drawImage(getImg(), getX() - 33, getY() - 50, null);
            //改变画笔颜色
            g.setColor(Color.GREEN);
            //绘制中心圆点
            g.fillOval(getX(), getY(), 10, 10);
            //绘制矩形边框
            g.drawRect(getX() - 23, getY() - 50, 60, 120);
            //绘制技能图片
            g.drawImage(abilityOne,getX() + 360,getY() + 180,null);
            g.drawImage(abilityTwo,getX() + 400,getY() + 40,null);
            g.drawImage(abilityThree,getX() + 520,getY() - 30,null);
            move();
        }
    }
}
